using System;
using UnityEngine;
using UnityEngine.UI;

public class UI : MonoBehaviour
{
	[Serializable]
	public class Bar
	{
		public RectTransform rectTransform;

		public Image image;

		[HideInInspector]
		public Vector2 deltaSize;

		public void Set()
		{
			deltaSize = rectTransform.sizeDelta;
		}
	}

	[Header("Health")]
	[Header("Requirement")]
	public Bar dnaBar;

	public Bar healthBar;

	public Bar staminaBar;

	private Player player;

	public void Begin()
	{
		player = Library.player;
		healthBar.Set();
		staminaBar.Set();
		dnaBar.Set();
		UpdateDnaBar();
	}

	private void UpdateBar(Bar bar, float value, float max)
	{
		bar.image.fillAmount = Mathf.Clamp01(value / max);
	}

	public void UpdateDnaBar()
	{
		UpdateBar(dnaBar, Library.controller.DNA, 1f);
	}

	public void UpdateHealthBar()
	{
		UpdateBar(healthBar, player.health, player.maxHealth);
	}

	public void UpdateStaminaBar()
	{
		UpdateBar(staminaBar, player.stamina, 100f);
	}
}
